//
//  LGCancerPatientFollowView.m
//  HeartDisease_YHJK
//
//  Created by 1234 on 2024/12/18.
//

#import "LGCancerPatientDetailFollowView.h"
@interface LGCancerPatientDetailFollowView()
/**   */
@property (nonatomic , strong)UIView *baseView;
/**   */
@property (nonatomic , strong)UIImageView *iconView;
/**   */
@property (nonatomic , strong)UILabel *titleLabel;
/**   */
@property (nonatomic , strong)UILabel *emptyLabel;
/**   */
@property (nonatomic , strong)NSMutableArray *dateArray;

@end

@implementation LGCancerPatientDetailFollowView

-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        [self setShadoWithColor:@"#B2BDC7" offset:CGSizeMake(0, 4) opacity:0.2 radius:15];
        [self addSubview:self.iconView];
        [self addSubview:self.titleLabel];
        [self addSubview:self.emptyLabel];
        [self addSubview:self.moreBtn];
        [self addSubview:self.auditBtn];
        [self addSubview:self.addButton];
    }
    return  self;
}

-(void)setDataDic:(NSDictionary *)dataDic{
    _dataDic = dataDic;
    NSArray *planArray = (dataDic.allKeys.count>0)?dataDic[@"items"]:@[];
    NSString *checked = LGNSString(dataDic[@"is_checked"]);
    if (planArray.count > 0) {
        //有随访
        self.emptyLabel.hidden = YES;
        self.addButton.hidden = YES;
        self.moreBtn.hidden = [checked isEqualToString:@"1"]?NO:YES;
        self.auditBtn.hidden = [checked isEqualToString:@"1"]?YES:NO;
        NSString *title = [kRoleId isEqualToString:@"10"]?@"进入审核":@"待审核";
        [self.auditBtn setTitle:title forState:UIControlStateNormal];
    }else{
        //没有随访
        self.emptyLabel.hidden = NO;
        self.addButton.hidden = NO;
        self.moreBtn.hidden = YES;
    }
    for (UILabel *label in self.dateArray) {
        [label removeFromSuperview];
    }
    [self.dateArray removeAllObjects];
    for (NSInteger i=0; i<planArray.count; i++) {
        NSDictionary *tempDic = planArray[i];
        NSString *date = LGNSString(tempDic[@"date"]);
        NSString *content = [NSString stringWithFormat:@"%@  %@",tempDic[@"date"],tempDic[@"status_name"]];
        NSString *colorStr = [LGNSString(tempDic[@"status"]) isEqualToString:@"3"]?@"#FF3B30":@"#909399";
        UILabel *label = [UILabel lableWithText:content colorString:colorStr textFont:LGFont(14) textAlignment:NSTextAlignmentLeft lines:1];
        label.frame = CGRectMake(viewPix(12), viewPix(43)+viewPix(25)*i, viewPix(150), viewPix(25));
        label.attributedText = [content attributeString:@{NSForegroundColorAttributeName:[UIColor colorWithString:@"#333333"]} range:NSMakeRange(0, date.length)];
        [self addSubview:label];
        [self.dateArray addObject:label];
    }
    NSInteger count = planArray.count>0?planArray.count:1;
    self.frame = CGRectMake(viewPix(16), self.frame.origin.y, Screen_W-viewPix(32), viewPix(55)+viewPix(25)*count);
}

#pragma mark
#pragma mark ====> 创建控件
-(NSMutableArray *)dateArray{
    if(!_dateArray){
        _dateArray = [NSMutableArray array];
    }
    return _dateArray;
}
-(UIView *)baseView{
    if(!_baseView){
        _baseView = [UIView shadowViewWithColor:@"#B2BDC7" offset:CGSizeMake(0, 5) opacity:0.2 radius:15];
        _baseView.backgroundColor = [UIColor whiteColor];
    }
    return _baseView;
}

-(UIImageView *)iconView{
    if(!_iconView){
        _iconView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"患者档案-随访及医嘱记录"]];
        _iconView.frame = CGRectMake(viewPix(11), viewPix(13), viewPix(24), viewPix(24));
    }
    return _iconView;
}

-(UILabel *)titleLabel{
    if(!_titleLabel){
        _titleLabel = [UILabel lableWithText:@"随访计划" colorString:@"#333333" textFont:LGFontWeight(18, UIFontWeightMedium) textAlignment:NSTextAlignmentLeft lines:1];
        _titleLabel.frame = CGRectMake(viewPix(41), viewPix(12), viewPix(100), viewPix(25));
    }
    return _titleLabel;
}

-(UILabel *)emptyLabel{
    if(!_emptyLabel){
        _emptyLabel = [UILabel lableWithText:@"暂无随访计划" colorString:@"#666666" textFont:LGFont(14) textAlignment:NSTextAlignmentLeft lines:1];
        _emptyLabel.frame = CGRectMake(viewPix(12), viewPix(43), viewPix(100), viewPix(20));
    }
    return _emptyLabel;
}

-(UIButton *)moreBtn{
    if(!_moreBtn){
        _moreBtn = [UIButton buttonWithTitle:@"查看全部" titleFont:LGFont(13) textColor:@"#909399" imageName:@"grayTip16"];
        _moreBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
        _moreBtn.frame = CGRectMake(Screen_W-viewPix(100)-viewPix(32), viewPix(10), viewPix(88), viewPix(30));
        [_moreBtn setButtonInsetsStyle:LGButtonInsetsStyleRight marginSpace:3];
        _moreBtn.hidden = YES;
    }
    return _moreBtn;
}


-(UIButton *)auditBtn{
    if(!_auditBtn){
        _auditBtn = [UIButton buttonWithBackColor:@"#5E8EF5" cornerRadius:viewPix(15) title:@"进入审批" titleFont:LGFont(14) textColor:@"#FFFFFF" frame:CGRectMake(Screen_W-viewPix(82)-viewPix(32), viewPix(10), viewPix(70), viewPix(30))];
        _auditBtn.hidden = YES;
    }
    return _auditBtn;
}

-(UIButton *)addButton{
    if(!_addButton){
        _addButton = [UIButton buttonWithBackColor:@"#5E8EF5" cornerRadius:viewPix(15) title:@"+ 新增随访计划" titleFont:LGFont(14) textColor:@"#FFFFFF" frame:CGRectMake(Screen_W-viewPix(127)-viewPix(32), viewPix(10), viewPix(115), viewPix(30))];
        _addButton.hidden = YES;
    }
    return _addButton;
}

@end
